package com.glc.gao.gavin.rxjavademo.operator;

import android.view.View;

import com.glc.gao.gavin.rxjavademo.R;

import java.util.Random;

import io.reactivex.Single;
import io.reactivex.SingleObserver;
import io.reactivex.disposables.Disposable;

public class SingleActivity extends BaseActivity {
    @Override
    public int getDescribeText() {
        return R.string.describe_single;
    }

    @Override
    protected int getContextView() {
        return R.layout.activity_single;
    }

    public void executeSingle(View view) {
        Single.just(new Random().nextInt())
                .subscribe(new SingleObserver<Integer>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onSuccess(Integer integer) {
                        print("onSuccess : " + integer);
                    }

                    @Override
                    public void onError(Throwable e) {
                        print("onError : " + e.getMessage());
                    }
                });
    }
}
